/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.perspecte.vsflean.ui.backingbeans;

import com.perspecte.vsflean.app.pojo.QualityReport;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.context.FacesContext;

/**
 *
 * @author Sandeep
 */
public class QualityReportUI implements Serializable{

    private List<QualityReport> sales;

    public List<QualityReport> getSales() {
        return sales;
    }

    /** Creates a new instance of QualityReport */
    public QualityReportUI() {
//        createDynamicColumns();
        populateQualityReport();
        sales = new ArrayList<QualityReport>();
        sales.add(new QualityReport("Brand 1", "A", "A", "A", 5, "A", "A"));
        sales.add(new QualityReport("Brand 2", "B", "B", "B", 6, "B", "B"));
        sales.add(new QualityReport("Brand 3", "C", "C", "C", 7, "C", "C"));
        sales.add(new QualityReport("Brand 4", "D", "D", "D", 8, "D", "D"));

    }
    private List<String> columns;
    private String columnName;
    private List<QualityReport> qualityReportList = new ArrayList<QualityReport>();

    private void createDynamicColumns() {
        columns = new ArrayList<String>();

        for (int i = 0; i < QualityReport.class.getDeclaredFields().length; i++) {

            columns.add(QualityReport.class.getDeclaredFields()[i].getName());
            System.out.println("Column Name:" + QualityReport.class.getDeclaredFields()[i].getName());
        }
    }

    private void populateQualityReport() {
        QualityReport qr = new QualityReport();
        qr.setCellName("Line1");
        qr.setItemNo("Item1");
        qr.setProductName("ProductA");
        qr.setReworkCause("ReasonA");
        qr.setReworkCauseType("ReworkTypeA");
        qr.setReworkCount(1);
        qr.setReworkTime("Jan 2, 2011 11:30AM");
        System.out.println("Inside populate");
        qualityReportList.add(qr);
        qr = new QualityReport();
        qr.setReworkCause("ReasonB");
        qr.setReworkCauseType("ReworkTypeB");
        qr.setReworkCount(5);
        qr.setCellName("Line2");
        qualityReportList.add(qr);
        
        qualityReportList.add(qr);
        qualityReportList.add(qr);
        qualityReportList.add(qr);
        qualityReportList.add(qr);
        qualityReportList.add(qr);
        qualityReportList.add(qr);
        qualityReportList.add(qr);
        System.out.println("After populate");
    }

    public void removeColumn() {
        String columnToRemove = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("columnToRemove");
        columns.remove(columnToRemove);
//        populateQualityReport();
    }

    /**
     * @return the columns
     */
    public List<String> getColumns() {
        return columns;
    }

    /**
     * @param columns the columns to set
     */
    public void setColumns(List<String> columns) {
        this.columns = columns;
    }

    /**
     * @return the columnName
     */
    public String getColumnName() {
        return columnName;
    }

    /**
     * @param columnName the columnName to set
     */
    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    /**
     * @return the qualityReportList
     */
    public List<QualityReport> getQualityReportList() {
        return qualityReportList;
    }
}
